package com.study.example.huawei;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main02 {

    public static void main(String[] args) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        String str = bufferedReader.readLine();
        String[] strings = str.split("#");
        int result = 0;
        if (strings.length>0){
            int[] result01 = new int[strings.length];
            for (int i = 0; i < strings.length; i++) {
                result01[i] = getNum02(strings[i].split("\\$"));
            }
            result = getNum01(result01);
        } else {//都是$
            result = getNum02(str.split("\\$"));
        }
        System.out.print(result);
    }

    //#计算方法
    private static int getNum01(String[] x ){
        if (x.length == 0){
            return 0;
        }
        int result = Integer.valueOf(x[0]).intValue();
        if (x.length>1){
            for (int i = 1; i < x.length ; i++) {
                result = 2*result + 3*Integer.valueOf(x[i]).intValue() + 4;
            }
        }
        return result;
    }

    //#计算方法
    private static int getNum01(int[] x ){
        if (x.length == 0){
            return 0;
        }
        int result = x[0];
        if (x.length>1){
            for (int i = 1; i < x.length ; i++) {
                result = 2*result + 3*x[i] + 4;
            }
        }
        return result;
    }

    //$计算方法
    private static int getNum02(String[] x ){
        if (x.length == 0){
            return 0;
        }
        int result = Integer.valueOf(x[0]).intValue();
        if (x.length>1){
            for (int i = 1; i < x.length ; i++) {
                result = 3*result + Integer.valueOf(x[i]).intValue() + 2;
            }
        }
        return result;
    }
}
